public class MyClass
{
    private static MyClass instance = null;
    private static int count = 0;

    private MyClass()
    {
        count++;
        System.out.println("第" + count + "个实例");
    }

    public static MyClass getInstance()
    {
        if (instance == null)
        {
            instance = new MyClass();
        }
        return instance;
    }

    public static void main(String[] args)
    {
        MyClass myClass;
        for (int i = 0; i < 5; i++)
        {
            myClass = MyClass.getInstance();
        }
    }
}
